<?php
    require_once 'core/config.php';
    require_once 'core/string_helper.php';
    require_once 'core/file_helper.php';
    require_once 'core/url_helper.php';
    $reporter = $_POST['reporter'];
	if ($_FILES["report_files"]["type"] != "application/zip" && $_FILES["report_files"]["type"] != "application/gzip") {
	    echo "The file type is not allowed";
	}
	if ($_FILES["report_files"]["error"] > 0) {
	    echo "Return Code: " . $_FILES["report_files"]["error"] . "\n";
	} else {
	    echo "Upload: " . $_FILES["report_files"]["name"] . "\n";
	    echo "Type: " . $_FILES["report_files"]["type"] . "\n";
	    echo "Size: " . ($_FILES["report_files"]["size"] / 1024) . " Kb\n";
	    echo "Temp file: " . $_FILES["report_files"]["tmp_name"] . "\n";

	    if (!file_exists("upload/")) {
	        mkdir("upload/");
	    }
        $new_name = random_string('md5').".zip";
        $new_path = path_join(FILE_UPLOAD_PATH, $new_name);
	    move_uploaded_file($_FILES["report_files"]["tmp_name"], $new_path);
	    echo "Stored in: " . "upload/" . $_FILES["report_files"]["name"] . "\n";
        $start_time = date("Y-m-d h:i:s");
        $command = path_join(APPPATH,"/background_process.php ").$new_path." $reporter '".$start_time."' 2>&1";
        system($command);
        echo "Success! Please visite:\nURL:".site_url("index.php?time=".$start_time) . "\n";
	}

?>